using System.Linq;
using DeploymentWang.Interfaces;
using DeploymentWang.Interfaces.Entities;

namespace DeploymentWang.Core.Readers
{
    public class UrlReaderExcel : ExcelReaderBase<UrlTarget>, IReader<UrlsRequest, UrlTargets>
    {
        public UrlReaderExcel(string filename)
            : base(filename)
        {
        }

        public bool Read(UrlsRequest request, out UrlTargets urls)
        {
            var data = GetData(request.Worksheet).Cast<UrlTarget>();

            urls = new UrlTargets();
            urls.AddRange((from s in data where !string.IsNullOrEmpty(s.Url) select s));

            return (urls.Count > 0);
        }
    }
}